﻿<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    <thead>
        <tr>
            <th width="8%">Số thứ tự</th>
            <th>Bình luận</th>
            <th>Tác giả</th>
            <th>Sản phẩm</th>
            <th>Ngày đăng</th>
            <th>Thao tác</th>
        </tr>
    </thead>
    <tbody>
    
    <?php
        for($i=0; $i<count($binhluan); $i++){
            $noi_dung =  $binhluan[$i]['noidung'];
                
                if(strlen($noi_dung)>=80){
                    $tom_tat = substr($noi_dung, 0, 80);
                    $index = strrpos($tom_tat, " " );
                    $tom_tat = substr($tom_tat, 0, $index+1)."...";
                }else{
                    $tom_tat = $noi_dung;
            }
            echo"<tr class='gradeU'>";
                echo"<td align='center'>".($i+1)."</td>";
                echo"<td><p title='$noi_dung'>".$tom_tat."</p></td>";
                echo"<td class='center'>".$binhluan[$i]['tendangnhap']."</td>";
                echo"<td>".$binhluan[$i]['tensanpham']."</td>";
                echo"<td class='center'>".$binhluan[$i]['ngaydang']."</td>";
                echo"<td class='center'><a title='Xóa tài khoản'><img lang='".$binhluan[$i]['mabinhluan']."' class='delBtn' src='".base_url()."images/trash.png' height='32' width='32' ></a></td>";
            echo"</tr>";
        }
    ?>
    </tbody>
</table>
<script type="text/javascript" src="<?=base_url()?>js/jquery.min.js"></script>
<script type="text/javascript" src="<?=base_url()?>js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$('#example').dataTable( {
			"aaSorting":[[4,'desc']],
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"aoColumns": [{"bSearchable": false, "bSortable": false},
						  {"sWidth":"35%"},
			              {"sWidth":"10%"},
			              null,
			              null,
			              {"bSearchable": false, "bSortable": false}]
		});
		
		$('.delBtn').hover(function(){
			$(this).attr('src','<?=base_url()?>images/trash_hover.png');
		}, function(){
			$(this).attr('src','<?=base_url()?>images/trash.png');
		});
		
		$('.delBtn').click(function(){
			var mabl = ($(this).attr('lang'));
			//alert(masp);
			var conf = confirm("Bạn muốn xóa bình luận?");
			if(conf == true){
				//alert(matk);
				$.post("<?=base_url()?>index.php/binhluan_controller/xoabinhluan",{mabl:mabl},function(data){
					//alert(matk);
					$('#noi_dung').html(data);
					//alert(masp);
					});
			}else{
				return false;
			}
		});
	})
</script>